package com.yc.spring;

import com.yc.spring.bbs.bean.Page;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

@Component
public class MyBeanPostProcessor implements BeanPostProcessor {
    @Override
    public Object postProcessBeforeInitialization(Object bean, String id) throws BeansException {
        // 对象创建之后, 初始化对象之前
        // 当前方法不做处理
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String id) throws BeansException {
        // 对象创建之后, 初始化对象之后
        if(bean instanceof Page){
            Page page = (Page) bean;
            page.setTotal(10000);
        }
        return bean;
    }
}
